package com.fxkj.cloud.drms.infra.mq.mqtt;

import java.util.regex.Pattern;

/**
 * <p>description: mqtt参数配置</p>
 * @author ww
 * @date 2025/3/14 11:33
 */
public interface MqttConstants {

    //主题配置
    interface Topic {

        //共享主题 $share/{group-name}/
        String SHARED_GROUP_TOPIC_PREFIX = "$share/fxkj/";
        String QUEUE_TOPIC_PREFIX = "$queue/";

        //接收设备消息主题配置
        interface Receive {
            //设备发送给服务端 前缀
            String COMMON_DEVICE_PREFIX = "device/";
            String COMMON_SHARE_DEVICE_PREFIX = SHARED_GROUP_TOPIC_PREFIX + COMMON_DEVICE_PREFIX;

            /*--------------------------设备消息主题配置-----------------------------*/
            //设备数据上报  $share/device/+/data  + 为设备id
            String DEVICE_DATA_UPLOAD_TOPIC = COMMON_SHARE_DEVICE_PREFIX + "+/data";
            //设备数据上报过滤正则
            String DEVICE_DATA_UPLOAD_REGEX = "^" + COMMON_DEVICE_PREFIX + "(.+)/data$";
            Pattern DEVICE_DATA_UPLOAD_PATTERN = Pattern.compile(DEVICE_DATA_UPLOAD_REGEX);
            //处理器名称
            String DEVICE_MSG_RECEIVER_SERVICE_NAME = "deviceMsgReceiverHandler";

            /*--------------------------设备计划指令下发回应主题配置-----------------------------*/
            //设备计划指令下发回应  $share/device/+/command/callback  + 为设备id
            String DEVICE_PLAN_COMMAND_RESPONSE_TOPIC = COMMON_DEVICE_PREFIX + "+/command/response";
            //设备计划指令下发回应过滤正则
            String DEVICE_PLAN_COMMAND_RESPONSE_REGEX = "^" + COMMON_DEVICE_PREFIX + "(.+)/command/response$";
            Pattern DEVICE_PLAN_COMMAND_RESPONSE_PATTERN = Pattern.compile(DEVICE_PLAN_COMMAND_RESPONSE_REGEX);
            //处理器名称
            String DEVICE_PLAN_COMMAND_RESPONSE_SERVICE_NAME = "devicePlanCommandResponseHandler";

            /*--------------------------设备告警主题配置-----------------------------*/
            //设备告警  $share/device/+/alarm  + 为设备id
            String DEVICE_ALARM_CREATE_TOPIC = COMMON_DEVICE_PREFIX + "+/alarm/create";

            //设备告警过滤正则
            String DEVICE_ALARM_CREATE_REGEX = "^" + COMMON_DEVICE_PREFIX + "(.+)/alarm/create$";
            Pattern DEVICE_ALARM_CREATE_PATTERN = Pattern.compile(DEVICE_ALARM_CREATE_REGEX);
            //处理器名称
            String DEVICE_ALARM_CREATE_SERVICE_NAME = "deviceAlarmCreateHandler";

            /*--------------------------设备告警关闭主题配置-----------------------------*/
            //设备告警  $share/device/+/alarm  + 为设备id
            String DEVICE_ALARM_CLOSE_TOPIC = COMMON_DEVICE_PREFIX + "+/alarm/close";
            //设备告警过滤正则
            String DEVICE_ALARM_CLOSE_REGEX = "^" + COMMON_DEVICE_PREFIX + "(.+)/alarm/close$";
            Pattern DEVICE_ALARM_CLOSE_PATTERN = Pattern.compile(DEVICE_ALARM_CLOSE_REGEX);
            //处理器名称
            String DEVICE_ALARM_CLOSE_SERVICE_NAME = "deviceAlarmCloseHandler";
        }

        //下发消息主题配置
        interface Send {
            //服务端下发给设备 前缀
            String SERVER_PREFIX = "server/";
            //指令下发
            String COMMAND_SEND = SERVER_PREFIX + "+/command";
            String CONTROL_PLAN_SEND = SERVER_PREFIX + "+/controlPlan";

            //查询下发
            String QUERY_SEND = SERVER_PREFIX + "+/query";

            //告警项设置
            String ALARM_ITEM_SEND = SERVER_PREFIX + "+/alarm/setting";

        }

        //管理端
        interface System {
            String SYSTEM_PREFIX = "$SYS/";

            /*----------------------------系统消息主题配置-----------------------------*/

            //客户端上线管理
            String CLIENT_ONLINE_END = "brokers/+/clients/fxkj-device/+/connected";
            String CLIENT_ONLINE = SYSTEM_PREFIX + CLIENT_ONLINE_END;
            //处理器名称
            String SYSTEM_DEVICE_ONLINE_SERVICE_NAME = "systemDeviceOnlineHandler";
            //过滤正则
            String CLIENT_ONLINE_REGEX = "^\\$SYS/" + "brokers/(.+)/clients/fxkj-device/(.+)/connected$";
            Pattern CLIENT_ONLINE_PATTERN = Pattern.compile(CLIENT_ONLINE_REGEX);


            //客户端下线管理
            String CLIENT_OFFLINE_END = "brokers/+/clients/fxkj-device/+/disconnected";
            String CLIENT_OFFLINE = SYSTEM_PREFIX + CLIENT_OFFLINE_END;
            //处理器名称
            String SYSTEM_DEVICE_OFFLINE_SERVICE_NAME = "systemDeviceOfflineHandler";
            //过滤正则
            String CLIENT_OFFLINE_REGEX = "^\\$SYS/" + "brokers/(.+)/clients/fxkj-device/(.+)/disconnected$";
            Pattern CLIENT_OFFLINE_PATTERN = Pattern.compile(CLIENT_OFFLINE_REGEX);
        }


        /*--------------------------订阅主题配置-----------------------------*/
        String[] SUBSCRIBE_TOPICS = new String[]{
                //todo 添加Mqtt客户端订阅主题
                //设备消息订阅
                Receive.DEVICE_DATA_UPLOAD_TOPIC,
                //系统消息订阅
                System.CLIENT_ONLINE,
                System.CLIENT_OFFLINE,
                //设备计划指令下发回应
                Receive.DEVICE_PLAN_COMMAND_RESPONSE_TOPIC,
                //设备告警
                Receive.DEVICE_ALARM_CREATE_TOPIC,
                Receive.DEVICE_ALARM_CLOSE_TOPIC
        };
    }
}
